package com.cll.learn.control.demo01;

import java.util.Random;
import java.util.concurrent.CountDownLatch;

/**
 * 描述信息:
 *
 * @author CLL
 * @version 1.0
 * @date 2021/5/15 16:55
 */
public class WaitThread implements Runnable {

    private final CountDownLatch countDownLatch;

    public WaitThread(CountDownLatch countDownLatch) {
        this.countDownLatch = countDownLatch;
    }

    @Override
    public void run() {
        // 随机的准备时长
        long prepareTime = new Random().nextInt(1000);
        System.out.println("线程：" + Thread.currentThread().getName() + "开始准备，准备时长" + prepareTime);
        try {
            Thread.sleep(prepareTime);
        } catch (InterruptedException e){
            e.printStackTrace();
        }
        System.out.println("线程：" + Thread.currentThread().getName() + "准备完成");
        countDownLatch.countDown();
    }
}
